<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Ajax Post取消请求</title>
</head>
<body>
    <button>点击发送</button>
    <button>点击取消</button>
    <script>
        // 获取元素节点
        const btn =document.getElementsByTagName("button");
        let x=null;
        btn[0].addEventListener("click",function(){
            // 1.创建xhr对象
            x =new XMLHttpRequest();
            // 2.创建 http 请求对象
            x.open("GET","http://127.0.0.1:8000/delay");
            // 3. 发送请求
            x.send();
        })
        btn[1].onclick=function(){
            x.abort();
        }
    </script>
</body>
</html>